package Week10;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;


public class PolyLine implements Geometry, Serializable {
	//A PolyLine is defined with an ArrayList of Points.
	
	//member variables
	protected ArrayList<POI> polypoints;
	String label;
	
	//constructor
	public PolyLine(String label){
		polypoints = new ArrayList<POI>();
		this.label = label;
	}
	
	//add point method harnessing the array list method
	public boolean add(POI newPOI) {return polypoints.add(newPOI);}
	
	//iterate through points in the array and print them harnessing iterator from arraylists
	public void printAll(){
		Iterator<POI> itr = polypoints.iterator(); 
		while(itr.hasNext()) {
			System.out.print(itr.next() + " ");
		}
	}

	public double computeArea() {
		return 0;
	}

	public double computeLength() {
		double totalLength = 0, segmentLength = 0;
		for(int i=0; i<polypoints.size()-1; i++){
        	segmentLength = 
        			Math.pow(
        					(
        						( Math.pow(polypoints.get(i).getPt().getX() - polypoints.get(i+1).getPt().getX(), 2) ) +
        						( Math.pow(polypoints.get(i).getPt().getY() - polypoints.get(i+1).getPt().getY(), 2) )
        						)
        					, 0.5);
        	totalLength = totalLength + segmentLength;
        }

		return totalLength;
	}

	public int computeDimension() {
		int dimension;
		if (polypoints.size() == 1){
			dimension = 0;}
		else if (polypoints.size() == 2){ 	//Should probably also check for equal slope between points
			dimension =  1;}
		else { 								//Should probably also check for equal slope between points
			dimension =  2;}
		return dimension;
	}

	//Getters and setters
	
	public ArrayList<POI> getPolypoints() {
		return polypoints;
	}

	public void setPolypoints(ArrayList<POI> polypoints) {
		this.polypoints = polypoints;
	}

	public String getLabel() {
		return label;
	}

	public void setLabel(String label) {
		this.label = label;
	}	
	
	
	
}
	


